package com.salefinder.server.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SaleFinderServiceHTTPImpl extends HttpServlet{

	@Override
	  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	      throws ServletException, IOException {

	    Random rnd = new Random();

	    PrintWriter out = resp.getWriter();
	    out.println('[');
	    String[] stockSymbols = req.getParameter("q").split(" ");
	    for (String stockSymbol : stockSymbols) {

	      double price = 0;
	      double change = 0;

	      out.println("  {");
	      out.print("    \"symbol\": \"");
	      out.print(stockSymbol);
	      out.println("\",");
	      out.print("    \"price\": ");
	      out.print(price);
	      out.println(',');
	      out.print("    \"change\": ");
	      out.println(change);
	      out.println("  },");
	    }
	    out.println(']');
	    out.flush();
	  }
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
	
	}
	
	@Override
	protected void doPut(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
	
	}
}
